********************************************************************************
** 	TITLE:		it2006_itanes_contact_networks                                ** 	
**  AUTHOR:	    Philippe Mongrain                                             **
**	DATA:       ITA2006_PRE_POST_NEW(vers_dic06).dta                          **
**	DATE:		October 2022 					                              **	
**	VERSION:	Stata 16					                                  **	
********************************************************************************

* Version control

version 16.0

* Open log file

capture log close       			  			              
log using "it2006_itanes_contact_networks", replace

* Open the dataset

use "ITA2006_PRE_POST_NEW(vers_dic06).dta", clear


***************************
** INDEPENDENT VARIABLES **
***************************

* Time

gen surveydate = date(a320,"YMD")

format %tdMon_DD,_CCYY surveydate

gen edate = 20060410

gen electiondate = date(string(edate,"%8.0f"),"YMD")

format %tdMon_DD,_CCYY electiondate

gen time = electiondate - surveydate

* Gender

gen male = a240

recode male (2=0)

* Age

gen birthyear = 1900 + a241

gen age = 2006 - birthyear

replace age = . if age < 17

* Education

gen education = a243

recode education (11=.)
recode education (12=.)

replace education = 1 if education == 1
replace education = 2 if education == 2
replace education = 3 if education == 3
replace education = 4 if education == 4
replace education = 5 if education == 5
replace education = 5 if education == 6
replace education = 5 if education == 7
replace education = 5 if education == 8
replace education = 6 if education == 9
replace education = 6 if education == 10

* Interest for politics

gen interest = a20

recode interest (5=.)
recode interest (6=.)

* Coalition preference

gen coalpref = 3 if b74 == 1
replace coalpref = 2 if b73 == 2
replace coalpref = 1 if b74 == 2 | b74 == 3

label define coalpref 1 "Loser coalition" 2 "No preference" 3 "Winner coalition"
label values coalpref coalpref

* Coalition preference scale

gen coalscale = .

replace coalscale = 1 if coalpref == 1 & b76 == 3
replace coalscale = 2 if coalpref == 1 & b76 == 2
replace coalscale = 3 if coalpref == 1 & b76 == 1
replace coalscale = 4 if coalpref == 2
replace coalscale = 5 if coalpref == 3 & b76 == 1
replace coalscale = 6 if coalpref == 3 & b76 == 2
replace coalscale = 7 if coalpref == 3 & b76 == 3

label define coalscale 1 "Strong loser preference" 2 "Moderate loser preference" 3 "Weak loser preference" 4 "No preference" 5 "Weak winner preference" 6 "Moderate winner preference" 7 "Strong winner preference" 
label values coalscale coalscale

* TV news attentiveness

gen tv = .

replace tv = 0 if a91 == 1
replace tv = 1 if a91 > 0 & a91 < 5
replace tv = 2 if a91 > 4 & a91 < 9
replace tv = 3 if a91 == 9
replace tv = . if a91 == 10

recode tv (.=-99)

* Radio news attentiveness

gen radio = .

replace radio = 0 if a95 == 1
replace radio = 1 if a95 > 0 & a95 < 5
replace radio = 2 if a95 > 4 & a95 < 9
replace radio = 3 if a95 == 9
replace radio = . if a95 == 10

recode radio (.=-99)

* Press news attentiveness

gen press = a98

recode press (5=.)

replace press = press - 1

recode press (.=-99)

* News attentiveness index

egen news = rowmax(tv radio press)

recode news (-99=.)

* Council's President - Correct answer (Silvio Berlusconi) = 1, incorrect answer = 0

gen council = a120

replace council = 0 if council == 2 & council!=. // Incorrect answer
replace council = 0 if council == 3 & council!=. // Incorrect answer
replace council = 0 if council == 4 & council!=. // Incorrect answer
replace council = 1 if council == 1 & council!=. // Correct answer

* Chamber's President - Correct answer (Pierferdinando Casini), incorrect answer = 0

gen chamber = a121

replace chamber = 0 if chamber == 2 & chamber!=. // Incorrect answer
replace chamber = 0 if chamber == 3 & chamber!=. // Incorrect answer
replace chamber = 0 if chamber == 4 & chamber!=. // Incorrect answer
replace chamber = 1 if chamber == 1 & chamber!=. // Correct answer

* Minister of Foreign Affairs - Correct answer (Gianfranco Fini), incorrect answer = 0

gen foreign = a122

replace foreign = 0 if foreign == 2 & foreign!=. // Incorrect answer
replace foreign = 0 if foreign == 3 & foreign!=. // Incorrect answer
replace foreign = 0 if foreign == 4 & foreign!=. // Incorrect answer
replace foreign = 1 if foreign == 1 & foreign!=. // Correct answer

* Who elects the President of the Republic - Correct answer (deputies and senators, or Parliament, or Parliamentarians, or the Chamber and the Senate), incorrect answer = 0

gen elect = a123

replace elect = 0 if elect == 2 & elect!=. // Incorrect answer
replace elect = 0 if elect == 3 & elect!=. // Incorrect answer
replace elect = 0 if elect == 4 & elect!=. // Incorrect answer
replace elect = 1 if elect == 1 & elect!=. // Correct answer

* Number of deputies in the Chamber of Deputies - Correct or quite correct answer (630 or number between 600 and 700), incorrect answer = 0

gen deputies = a124

replace deputies = 0 if deputies == 3 & deputies!=. // Incorrect answer
replace deputies = 0 if deputies == 4 & deputies!=. // Incorrect answer
replace deputies = 0 if deputies == 5 & deputies!=. // Incorrect answer
replace deputies = 1 if deputies == 1 & deputies!=. // Correct answer
replace deputies = 1 if deputies == 2 & deputies!=. // Correct answer

* Political knowledge index

gen knowledge = council + chamber + foreign + elect + deputies

* Political discussion

gen discussion = a21 

recode discussion (7=.)
recode discussion (8=.)

replace discussion = discussion - 1

gen discussion_3pts = 0 if discussion == 1
replace discussion_3pts = 1 if discussion == 2
replace discussion_3pts = 1 if discussion == 3
replace discussion_3pts = 2 if discussion == 4
replace discussion_3pts = 2 if discussion == 5

* Political disagreement

gen relativesCasa = b180_2
gen coworkersCasa = b181_2
gen friendsCasa = b182_2
gen relativesUnion = b180_3
gen coworkersUnion = b181_3
gen friendsUnion = b182_3

recode relativesCasa coworkersCasa friendsCasa relativesUnion coworkersUnion friendsUnion (8=.)
recode relativesCasa coworkersCasa friendsCasa relativesUnion coworkersUnion friendsUnion (9=.)

replace relativesCasa = relativesCasa - 1
replace coworkersCasa = coworkersCasa - 1
replace friendsCasa = friendsCasa - 1
replace relativesUnion = relativesUnion - 1
replace coworkersUnion = coworkersUnion - 1
replace friendsUnion = friendsUnion - 1

gen disagreementCasa = relativesCasa + coworkersCasa + friendsCasa if coalpref == 3

gen disagreementUnion = relativesUnion + coworkersUnion + friendsUnion if coalpref == 1

egen disagreement = rowmax(disagreementCasa disagreementUnion)

replace disagreement = 0 if coalpref == 2

gen relativesCasa_3pts = relativesCasa
gen coworkersCasa_3pts = coworkersCasa
gen friendsCasa_3pts = friendsCasa
gen relativesUnion_3pts = relativesUnion
gen coworkersUnion_3pts = coworkersUnion
gen friendsUnion_3pts = friendsUnion

replace relativesCasa_3pts = 0 if relativesCasa == 1
replace relativesCasa_3pts = 1 if relativesCasa == 2
replace relativesCasa_3pts = 1 if relativesCasa == 3
replace relativesCasa_3pts = 2 if relativesCasa == 4
replace relativesCasa_3pts = 2 if relativesCasa == 5
replace relativesCasa_3pts = 2 if relativesCasa == 6

replace coworkersCasa_3pts = 0 if coworkersCasa == 1
replace coworkersCasa_3pts = 1 if coworkersCasa == 2
replace coworkersCasa_3pts = 1 if coworkersCasa == 3
replace coworkersCasa_3pts = 2 if coworkersCasa == 4
replace coworkersCasa_3pts = 2 if coworkersCasa == 5
replace coworkersCasa_3pts = 2 if coworkersCasa == 6

replace friendsCasa_3pts = 0 if friendsCasa == 1
replace friendsCasa_3pts = 1 if friendsCasa == 2
replace friendsCasa_3pts = 1 if friendsCasa == 3
replace friendsCasa_3pts = 2 if friendsCasa == 4
replace friendsCasa_3pts = 2 if friendsCasa == 5
replace friendsCasa_3pts = 2 if friendsCasa == 6

replace relativesUnion_3pts = 0 if relativesUnion == 1
replace relativesUnion_3pts = 1 if relativesUnion == 2
replace relativesUnion_3pts = 1 if relativesUnion == 3
replace relativesUnion_3pts = 2 if relativesUnion == 4
replace relativesUnion_3pts = 2 if relativesUnion == 5
replace relativesUnion_3pts = 2 if relativesUnion == 6

replace coworkersUnion_3pts = 0 if coworkersUnion == 1
replace coworkersUnion_3pts = 1 if coworkersUnion == 2
replace coworkersUnion_3pts = 1 if coworkersUnion == 3
replace coworkersUnion_3pts = 2 if coworkersUnion == 4
replace coworkersUnion_3pts = 2 if coworkersUnion == 5
replace coworkersUnion_3pts = 2 if coworkersUnion == 6

replace friendsUnion_3pts = 0 if friendsUnion == 1
replace friendsUnion_3pts = 1 if friendsUnion == 2
replace friendsUnion_3pts = 1 if friendsUnion == 3
replace friendsUnion_3pts = 2 if friendsUnion == 4
replace friendsUnion_3pts = 2 if friendsUnion == 5
replace friendsUnion_3pts = 2 if friendsUnion == 6

gen disagreement_3pts = 0 if disagreement >= 0 & disagreement < 5
replace disagreement_3pts = 1 if disagreement >= 5 & disagreement < 10
replace disagreement_3pts = 2 if disagreement >= 10 & disagreement <= 15

* Main source of information

gen network_1 = a101_1

recode network_1 (9=.)

gen network_main = 1 if network_1 == 2

replace network_main = 0 if network_main!=1 & network_1!=.


*********************************
** NATIONAL-LEVEL EXPECTATIONS ** 
*********************************

* Generate variable identifying incomplete answers

gen winCoalitionA = a130_1
gen winCoalitionB = a130_2

recode winCoalitionA winCoalitionB (5=.)
recode winCoalitionA winCoalitionB (6=.)

gen complete_whole = 1 if winCoalitionA!=. & winCoalitionB!=.

* Generate value of 1 if the expectation for one coalition is higher or equal to the expectations for at least one other coalition

gen coalitionA = 1 if winCoalitionA >= winCoalitionB & complete_whole == 1

gen coalitionB = 1 if winCoalitionB >= winCoalitionA & complete_whole == 1

gen coalitionOTH = 1 if winCoalitionA == 1 & winCoalitionB == 1

replace coalitionA = . if coalitionOTH == 1 & complete_whole == 1
replace coalitionB = . if coalitionOTH == 1 & complete_whole == 1

* Generate variable for ambiguous forecasts

gen ambiguous_whole = .

replace ambiguous_whole = 99 if coalitionA == coalitionB & coalitionA!=.

replace ambiguous_whole = 99 if coalitionB == coalitionA & coalitionB!=.

* Generate value of 0 for lower expectations

replace coalitionA = 0 if coalitionA!=1 & coalitionA!=. & complete_whole == 1
replace coalitionB = 0 if coalitionB!=1 & coalitionB!=. & complete_whole == 1
replace coalitionOTH = 0 if coalitionOTH!=1 & coalitionOTH!=. & complete_whole == 1

* Forecasts (1 = Centre-left, 2 = Centre-right, 88 = other, 99 = ambiguous)

gen forecast_whole = .

replace forecast_whole = 1 if coalitionA == 1 & complete_whole == 1
replace forecast_whole = 2 if coalitionB == 1 & complete_whole == 1
replace forecast_whole = 88 if coalitionOTH == 1 & complete_whole == 1
replace forecast_whole = 99 if ambiguous_whole == 1 & complete_whole == 1

* Identify correct and ambiguous forecasts

gen correct_whole = 0 if forecast_whole!=1 & forecast_whole!=. & complete_whole == 1
replace correct_whole = 1 if forecast_whole == 1 & complete_whole == 1

replace correct_whole = 0 if a130_1 == 9 & a130_2 == 9

replace correct_whole = 99 if forecast_whole == 99 & coalitionA == 1 & complete_whole == 1

* Generate dichotomous variable (treat ambiguous forecasts as incorrect)

gen correct_whole_d = correct_whole

replace correct_whole_d = 0 if correct_whole_d == 99
replace correct_whole_d = 1 if correct_whole_d == 1


**********
** SAVE **
**********

save "it2006_itanes.dta", replace


*******************
** MAIN ANALYSES **
*******************

* Regression analysis and percentage of correct and incorrect forecasts

logistic correct_whole_d discussion disagreement coalscale interest news knowledge age i.male education time
estimates table, star(.05 .01 .001)

tab correct_whole_d if e(sample) == 1

* Summary statistics

label variable correct_whole_d "Coalition formed (DV)"
label variable discussion "Discussion"
label variable disagreement "Disagreement"
label variable coalscale "Coalition preference"
label variable interest "Interest"
label variable news "News attentiveness"
label variable knowledge "Political knowledge"
label variable age "Age"
label variable male "Gender (male = 1)"
label variable education "Education"
label variable time "Time of interview"

estpost tabstat correct_whole_d discussion disagreement coalscale interest news knowledge age male education time if e(sample) == 1, statistics(n mean p50 sd min max) columns(statistics)

esttab using "it2006_itanes_summary_national.tex", substitute("\begin{table}[htbp]" "\begin{table}[H]") cells("count(label(N) fmt(%9.0fc)) mean(fmt(%5.2f) label(Mean)) p50(fmt(%5.1f) label(Median)) sd(fmt(%5.1f) label(Std. dev.)) min(fmt(%5.1f) label(Min)) max(fmt(%5.1f) label(Max))") label width(\textwidth) nomtitle nonumber noobs booktabs title("Summary statistics -- 2006 Italian general election (ITANES), national level") replace

eststo clear


*************************
** ADDITIONAL ANALYSES **
*************************

* Regression analysis

logistic correct_whole_d i.network_main discussion disagreement coalscale interest news knowledge age i.male education time
estimates table, star(.05 .01 .001)

log close